#include <stdio.h>

int main() {
	int n = 0;
	int m = 0;
	int start = 0;
	int count = 0;
	scanf("%d %d %d", &n, &m, &start);
	char arr[20][20] = {0};
	int i = 0;
	int j = 0;
	for (i = 0; i < n; i++) {

		scanf("%s", &arr[i]);

	}
	int hang = 1;
	int lie = start;
	while (1) {
		if (arr[hang - 1][lie - 1] == 'W') {
			lie -= 1;
			arr[hang - 1][lie - 1 + 1] = 'A';
		} else if (arr[hang - 1][lie - 1] == 'E') {
			lie += 1;
			arr[hang - 1][lie - 1 - 1] = 'A';
		} else if (arr[hang - 1][lie - 1] == 'N') {
			hang -= 1;
			arr[hang - 1 + 1][lie - 1] = 'A';
		} else if (arr[hang - 1][lie - 1] == 'S') {
			hang += 1;
			arr[hang - 1 - 1][lie - 1] = 'A';
		}
		count++;
		if (hang == 0 || lie == 0 || hang > n || lie > m) {
			printf("out %d", count);
			return 0;
		}
		if (arr[hang - 1][lie - 1] == 'A') {
			printf("loop %d", count);
			return 0;
		}
	}

}